//
//  ReferrerViewController.m
//  WuJieLive
//
//  Created by 张瀚坤 on 2017/10/26.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "ReferrerViewController.h"
#import "ReferralViewController.h"

@interface ReferrerViewController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneText;
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;

@end

@implementation ReferrerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

-(void)setNavi
{
    self.title = @"修改推荐人";
}

-(void)setUI
{
    [self.phoneText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:(UIControlEventEditingChanged)];
}


- (void)textFieldDidChange:(UITextField *)textField
{
    
    if (self.phoneText.text.length == 11) {
        self.nextBtn.userInteractionEnabled = YES;
        [self.nextBtn setBackgroundColor:MainColor];
    }else
    {
        [self.nextBtn setBackgroundColor:MainBtnColor];
        self.nextBtn.userInteractionEnabled = NO;
    }
    
}

// 修改推荐人下一步 2f4b68faaf70b3cee9a5f4bdb8a3d1c3 是不是要这个key

- (IBAction)nextAction:(id)sender {
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary * dict = @{@"token":self.userToken,@"phone_mob":self.phoneText.text};
    [HTTPTool POSTForm:[NSString stringWithFormat:@"%@member/edit-reference",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (isSuccess) {
            ReferralViewController * vc = [[ReferralViewController alloc]init];
            vc.nickNameString = [[responseObject objectForKey:@"data"] objectForKey:@"user_name"];
            vc.telePhoneString = [[responseObject objectForKey:@"data"] objectForKey:@"phone_mob"];
            vc.headerImageString = [[responseObject objectForKey:@"data"] objectForKey:@"portrait"];
            vc.popType = 1;
            vc.referenceKey = [[responseObject objectForKey:@"data"] objectForKey:@"promoter_redis_key"];
            [self.navigationController pushViewController:vc animated:YES];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
